package groupon.web;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import groupon.service.ProductManager;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

public class InventoryController implements Controller{

	private ProductManager productManager;
	protected final Log log = LogFactory.getLog(InventoryController.class);

	public ModelAndView handleRequest(HttpServletRequest arg0,
			HttpServletResponse arg1) throws Exception {
		log.info("call page inventory");
		String now = (new Date()).toGMTString();
		Map<String, Object> model = new HashMap<String, Object>();
		model.put("now", now);
		model.put("products", this.productManager.getProducts());
		return new ModelAndView("inventory", "model", model);
	}
	
	 public void setProductManager(ProductManager productManager) {
	        this.productManager = productManager;
	    }

}
